#include<bits/stdc++.h>
using namespace std;

map<int, map<int, int>> mp;

int main()
{
	int d, n;
	int x, y, z;
	cin>>d>>n;
	while(n--)
	{
		cin>>x>>y>>z;
		mp[x][y] = z;
	}
	int ans = 0, mx = 0, cnt = 0;
	for(int i = 0;i <= 1024;i++)
	{
		for(int j = 0;j <= 1024;j++)
		{
			int mn_l = i-d;
			int mx_l = i+d;
			int mn_r = j-d;
			int mx_r = j+d;
			ans = 0;
			for(auto p1 = mp.begin();p1 != mp.end();p1++)
			{
				if(mn_l <= p1->first && p1->first <= mx_l)
				{
					for(auto p2 = p1->second.begin();p2 != p1->second.end();p2++)
					{
						if(mn_r <= p2->first && p2->first <= mx_r)
						{
							ans += mp[p1->first][p2->first];
						}
					}
				}
			}
			if(mx == ans)
				cnt++;
			else if(mx < ans)
			{
				mx = ans;
				cnt = 1;
			}
		}
	}
	cout<<cnt<<" "<<mx;
	cout<<endl;
	system("pause");
	return 0;
}

